<?php

require_once('../../../boot.inc.php');

// discarding output buffering
ob_end_clean();

require_once(TANGRA_MAIN_DIR.'filesystem_toolbox/filesystem_functions.inc.php');



if (array_key_exists('img', $_GET)) {
	$filename = $PATHS->get_scratch().'uploads/modules/extlib_js_fckeditor/'.$_GET['img'];

	if (file_exists($filename)) {

		$file_extension = strtolower(substr(strrchr($filename,"."),1));
		switch ($file_extension) {
		   case "gif": $ctype="image/gif"; break;
		   case "png": $ctype="image/png"; break;
		   case "jpe": case "jpeg":
		   case "jpg": $ctype="image/jpeg"; break;
		   default: $ctype="";
		}

		if ($ctype) {
			header('Last-Modified: '.date('r'));
			header('Accept-Ranges: bytes');
			header('Content-Length: '.filesize($filename));
			header('Content-Disposition: inline; filename="'.basename($filename).'"');
			header("Content-Type: $ctype");
			readfile("$filename") or die("File not found.");
		}
	} else {
		print('Cannot find image.');
	}
}
